<?php

namespace app\common\model;

use app\helpers\Common;
use app\libs\traits\BaseModelTrait;

use think\model\concern\SoftDelete;

class Test extends Base
{
    /**
     * Base Model Trait
     */
    use BaseModelTrait;

    use SoftDelete;

    protected $deleteTime = 'deleted_at';

    // 软删除字段默认值
    protected $defaultSoftDelete = 0;

    // 当前模型名称 不带前缀
    protected $name = 'test';

    public $pk = 'id';

    public function _admin_id()
    {
        $result = $this->belongsTo('app\common\model\VueAdmin', 'admin_id', 'id')->find();

        return $result['username'];
    }

    /**
     * 定义数据表中不存在的字段
     *
     * 第二个参数传入的是当前的所有数据数组
     */
    public function getAdminIdAttr($value, $data)
    {
        $username = \app\common\model\VueAdmin::where(['id' => $data['admin_id']])->value('username');

        return $username;
    }
}
